package com.aisoback.service.impl;


import com.aisoback.common.Code;
import com.aisoback.exception.BusinessException;
import com.aisoback.model.Request.QueryUserRequest;
import com.aisoback.service.UserService;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.aisoback.mapper.UserMapper;
import com.aisoback.model.User;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author qings
 * @description 针对表【user】的数据库操作Service实现
 * @createDate 2024-10-08 09:42:22
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User>
        implements UserService {
    @Resource
    private UserMapper userMapper;

    @Override
    public int addUser(String username, String userProfile) {
        User user = new User();
        user.setUsername(username);
        user.setUserProfile(userProfile);
        return userMapper.add(user);
    }

    @Override
    public Page<User> getUserList(QueryUserRequest queryUserRequest, int pageNum, int pageSize) {
        Page<User> page = new Page<>(pageNum, pageSize);
        String username = queryUserRequest.getUsername();
        if (StringUtils.isEmpty(username)) {
            return userMapper.selectPage(page, null);
        }
        return userMapper.getUserList(username, page);
    }


}




